<template>
	<view>
		<u-sticky bgColor="#6492FF" offsetTop=0 customNavHeight=0>
			<navbox title="我的钱包"></navbox>
		</u-sticky>
		<view class="con">
			<view class="con__box">
				<view class="con__box__top">
					<view class="con__box__title">
						提现金额
					</view>
					<view class="con__box__inpbox">
						<input placeholder="请输入提现金额" placeholder-style="font-size:26rpx;" type="number" v-model="price"
							class="con__box__inpbox__i" />
						元
					</view>
				</view>
				<view class="con__box__tx">
					<view class="con__box__ye">
						<view class="">
							账户余额：{{accountBalance.toFixed(2)}}元
						</view>
						<view class="" @click="price=accountBalance">
							全部提现
						</view>
					</view>
					<view class="con__box__ye" style="color: #6492ff;">
						提现说明：单月提现金额超过{{monthTxRange}}后，代扣税点{{txTaxFactor}}%
					</view>
					<view class="con__box__title">
						提现至
					</view>
					<view class="con__box__z">
						<view class="">
							提现账户
						</view>
						<view class="u-flex u-flex-y-center" @click="navto('/pages/my/account?accountid='+accountid)">
							<view class="con__box__zh">
								{{account}}
							</view>
							<view class="" v-if="account">
								修改
							</view>
							<view class="" v-else>
								去绑定
							</view>
							<image src="/static/img/home/more.png" class="con__box__more" mode=""></image>
						</view>
					</view>
				</view>
				<view class="con__box__footer">
					<u-button text="立即提现" @click="submit" color="#6492FF" shape='circle'></u-button>
				</view>
			</view>

			<view class="con__box" style="padding-bottom: 80rpx;">
				<view class="con__box__it">
					<view class="con__box__title">
						提现记录
					</view>
					<view class="con__box__gd" @click="navto('/pages/my/purselist')">
						查看更多>>
					</view>
				</view>
				<view class="" v-if="list.length>0">
					<view class="con__box__item" v-for="(item,index) in list" :key="index">
						<view class="u-flex u-flex-y-center u-flex-between">
							<view class="">
								余额提现
							</view>
							<view class="">
								{{item.price.toFixed(2)}}元
							</view>
						</view>
						<view class="u-flex u-flex-y-center u-flex-between">
							<view class="">
								{{item.buildTime}}
							</view>
							<view class="" v-if="item.status==0">
								提现中
							</view>
							<view class="" v-if="item.status==1">
								提现成功
							</view>
							<view class="" v-if="item.status==2">
								提现失败
							</view>
							<view class="" v-if="item.status==3">
								待审核
							</view>
						</view>
						<view class="u-flex u-flex-y-center u-flex-between" v-if="item.status==2">
							<view class="">
								{{item.failMsg}}
							</view>
					
						</view>
					</view>
				</view>
				<view class="" v-else style="margin-top: 200rpx;">
					<u-empty icon="/static/img/index/empty.png" mode="data" text="暂时没有数据"></u-empty>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import md5 from 'js-md5'
	import {
		queryAccount,
		txlist,
		tx
	} from '@/api/user.js'
	export default {
		data() {
			return {
				account: null,
				accountBalance: 0,
				price: null,
				list: [],
				monthTxRange: 0,
				txTaxFactor: 0,
				pageSize: 10,
				pageNum: 1,
				accountid:''
			};
		},
		onShow() {
			queryAccount().then(res => {
				if (res.data.code == 200) {
					this.accountBalance = res.data.data.customer.accountBalance
					this.monthTxRange = res.data.data.monthTxRange
					this.txTaxFactor = res.data.data.txTaxFactor
					if (res.data.data.accounts.length > 0) {
						this.account = res.data.data.accounts[0].account
						this.accountid = res.data.data.accounts[0].id
						
					}
				}
			})
		},
		onLoad() {
			// 查询提现账户
			this.getlist()

		},
		methods: {
			getlist() {
				txlist().then(res => {
					if (res.data.code == 200) {
						this.list = res.data.data
					}
				})
			},
			submit() {
				let _this=this
				if (!this.price) {
					this.$u.toast('提现金额不能为空')
					return
				}
				if (!this.account) {
					this.$u.toast('请绑定银行卡')
					return
				}
				// 加密 MD5
				let sign=md5(`account=${this.account}&price=${this.price}222222`)
				// console.log(sign)
				// return
				tx({
					price: this.price,
					account: this.account,
					sign
				}).then(res => {
					if (res.data.code == 200) {
						this.accountBalance -= this.price
						_this.$u.toast('提现成功')
						_this.getuserinfo()
						_this.getlist()
					} else {
						this.$u.toast('提现失败')
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f6f6f6;
	}

	.con {
		padding: 25rpx 16rpx;

		&__box {
			padding: 0 40rpx;
			background: #FFFFFF;
			border-radius: 14rpx;
			margin-bottom: 25rpx;

			&__top {
				padding: 34rpx 0 20rpx;
				border-bottom: 1rpx solid rgba(205, 205, 205, .5);

			}

			&__title {
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 34rpx;
				color: #3E3D3D;
				line-height: 34rpx;
			}

			&__inpbox {
				margin-top: 26rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #3E3D3D;
				line-height: 26rpx;

				&__i {
					width: 80%;
					font-family: Source Han Sans SC;
					font-weight: 400;
					font-size: 26rpx;
					line-height: 26rpx;
					font-size: 26rpx;
					color: #707070;
				}
			}

			&__ye {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 25rpx;
				color: #707070;
				line-height: 25rpx;
				margin: 24rpx 0;
			}

			&__tx {
				border-bottom: 1rpx solid rgba(205, 205, 205, .5);
				padding-bottom: 20rpx;
			}

			&__z {
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #707070;
				line-height: 26rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				margin-top: 36rpx;
			}

			&__zh {
				font-family: Source Han Sans SC;
				font-weight: bold;
				font-size: 26rpx;
				color: #6492FF;
				line-height: 26rpx;
				margin-right: 10rpx;
			}

			&__more {
				width: 15rpx;
				height: 21rpx;
				margin-left: 6rpx;
			}

			&__footer {
				padding: 25rpx 58rpx 34rpx;
			}

			&__it {
				padding: 25rpx 0 25rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;
			}

			&__gd {
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 25rpx;
				color: #707070;
				line-height: 25rpx;
			}

			&__item {
				padding: 25rpx 0;
				height: 66rpx;
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 26rpx;
				color: #3E3D3D;
				line-height: 26rpx;
				border-bottom: 1rpx solid rgba(112, 112, 112, .4);
			}
		}
	}
</style>